<?php
namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;

class UserController extends Controller{

    // 查询数据
    public function testquery(){

        // 返回所有数据
          $users=DB::select("select * 
            from smbms_user");
         dd($users);
    }

    // 新增数据
    public function testInsert(){
        // 插入一条数据
        $sql="insert into smbms_user 
        (userName,userPassword,phone)
        values(?,?,?)";
        // 插入数组，对应占位符
        $bool= DB::insert($sql,[
            "laravel","121212",15201547891
            ]);
        var_dump($bool);
    }
    // 修改数据
    public function testUpdate(){
        $sql="update smbms_user
            set
                userName=?,address=?
            where 
                id=?";

         // 修改数组，对应占位符
         $bool=DB::update($sql,[
            "laravel2",
            "qwswedaw",
            16
         ]);
         var_dump($bool);
    }
    // 删除数据
    public function testDelete($id){
        $sql="delete 
        from smbms_user
        where id=?";

        $bool=DB::delete($sql,[
            $id
        ]);
        var_dump($bool);
    }
}